﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DreamBuilder.Common;
using DreamBuilder.Core.DAO;
using System.Data.Common;
using CommonModule;

namespace Web.SystemConfig.WorkFlow
{
    public class WorkFlowMessageStatusDAL : DataHelper
    {
        /// <summary>
        /// 获取所有驱动规则
        /// </summary>
        /// <param name="dataTable"></param>
        /// <returns></returns>
        public string GetAllWorkFlowMessageStatus(out DataTable dataTable)
        {
            dataTable = null;
            string rtnString = string.Empty;
            try
            {
                string sql = string.Format(@"select   t.TableID,
                                                                       t.TableName,
                                                                       t.DefaultStatusID,
                                                                       m.STATUSID,
                                                                       m.STATUSNAME 
                                                                from workflow_messagestatus m,
                                                                     WorkFlow_Table t
                                                                where m.tableid=t.tableID");
                DataSet oDataSet = DBHelper.ExecuteDataSet(sql);
                if (oDataSet != null && oDataSet.Tables.Count > 0)
                {
                    dataTable = oDataSet.Tables[0];
                }
            }
            catch(Exception ex)
            {
                rtnString = ex.Message;
            }
            return rtnString;
        }

        /// <summary>
        /// 获取所有操作规则
        /// </summary>
        /// <param name="dataTable"></param>
        /// <returns></returns>
        public string GetAllWorkFlowOperateRule(out DataTable dataTable)
        {
            dataTable = null;
            string rtnString = string.Empty;
            try
            {
                        string sql = string.Format(@"select 
                                                                       (select TABLEID from WORKFLOW_MESSAGESTATUS m where m.StatusID=r.FromStatusID) as TableID,
                                                                       r.OperateID,
                                                                       r.OperateName,
                                                                       R.FromStatusID,
                                                                       (select StatusName from WORKFLOW_MESSAGESTATUS m where m.StatusID=r.FromStatusID) as FromStatusName,
                                                                       r.ToStatusID,
                                                                       (select StatusName from WORKFLOW_MESSAGESTATUS m where m.StatusID=r.TOStatusID) as ToStatusName,
                                                                        r.ToRoleID,
                                                                        r.FromRoleID
                                                                   from 
                                                                        workflow_operaterule r");
                DataSet oDataSet = DBHelper.ExecuteDataSet(sql);
                if (oDataSet != null && oDataSet.Tables.Count > 0)
                {
                    dataTable = oDataSet.Tables[0];
                }
            }
            catch (Exception ex)
            {
                rtnString = ex.Message;
            }
            return rtnString;
        }
    }
}